// 云函数入口文件
const cloud = require('wx-server-sdk');
const _ = require('lodash');

cloud.init();
const db = cloud.database();
const dbcommand = db.command;

// 云函数入口函数
exports.main = async (event, context) => {
  const { code, page_no, page_size } = event;
  const wxContext = cloud.getWXContext();
  const result = await db.collection('garbage').where({
    category: dbcommand.in(code)
  })
  .skip(page_no * page_no)
  .limit(page_size)
  .get();
  _.forEach(result.data, item => {
    item.text = item.name;
  });
  return result.data;
}